package com.ido.otaclient.fontb;

import android.content.Context;

import com.ido.otaclient.base.BasePreference;
import com.ido.otaclient.env.AppEnv;

/**
 * Copyright (c) 2019 深圳市爱都科技有限公司. All rights reserved.
 *
 * @Author: xyb
 * @CreateDate: 2020-03-07 11:47
 * @description
 */
public class FontBPerference extends BasePreference {
    private static final String NAME = "fontb_preference";

    private static final String TASK_NAME = "taskName";
    private static final String FIREWARE_NEW_NAME = "firewareNewName";
    private static final String FIREWARE_NEW_VERSION = "firewareNewVersion";
    private static final String FIREWARE_NEW_PATH = "firewareNewPath";
    private static final String BOOTLOADER_NAME = "bootloaderName";
    private static final String BOOTLOADER_VERSION = "bootloaderVersion";
    private static final String BOOTLOADER_PATH = "bootloaderPath";
    private static final String FONT_NAME ="fontName";
    private static final String FONT_NAME_VERSION ="fontVersion";
    private static final String FONT_PATH = "fontPath";
    private static final String DEVICE_ID = "deviceId";
    /**
     * 升级配置
     */
    private FontBConfig mFontBConfig;

    private static volatile FontBPerference instance;

    private static Context getContext() {
        return AppEnv.instance().getContext();
    }

    public static FontBPerference getInstance() {
        if (instance == null) {
            synchronized (FontBPerference.class) {
                if (instance == null) {
                    instance = new FontBPerference();
                }
            }
        }
        return instance;
    }

    /**
     * 保存配置在本地
     * @param fontBConfig
     */
    public void saveFontBConfig(FontBConfig fontBConfig){
        if(fontBConfig == null){
            fontBConfig = new FontBConfig();
        }
        saveString(getContext(),NAME,TASK_NAME,fontBConfig.getTaskName());
        saveString(getContext(),NAME,FIREWARE_NEW_NAME,fontBConfig.getFirewareNewName());
        saveString(getContext(),NAME,FIREWARE_NEW_VERSION,fontBConfig.getFirewareNewVersion());
        saveString(getContext(),NAME,BOOTLOADER_NAME,fontBConfig.getBootloaderName());
        saveString(getContext(),NAME,BOOTLOADER_VERSION,fontBConfig.getBootloaderVersion());
        saveString(getContext(),NAME,FONT_NAME,fontBConfig.getFontName());
        saveString(getContext(),NAME,FONT_NAME_VERSION,fontBConfig.getFontVersion());
        saveString(getContext(),NAME,FIREWARE_NEW_PATH,fontBConfig.getFirewareNewPath());
        saveString(getContext(),NAME,BOOTLOADER_PATH,fontBConfig.getBootloaderPath());
        saveString(getContext(),NAME,FONT_PATH,fontBConfig.getFontPath());
        saveString(getContext(),NAME,DEVICE_ID,fontBConfig.getDeviceId());
        mFontBConfig = fontBConfig;
    }

    /**
     * 从本地取出数据
     * @return
     */
    public FontBConfig getFontBConfig(){
        mFontBConfig = new FontBConfig();
        mFontBConfig.setTaskName(getString(getContext(),NAME,TASK_NAME));
        mFontBConfig.setFirewareNewName(getString(getContext(),NAME,FIREWARE_NEW_NAME));
        mFontBConfig.setFirewareNewVersion(getString(getContext(),NAME,FIREWARE_NEW_VERSION));
        mFontBConfig.setBootloaderName(getString(getContext(),NAME,BOOTLOADER_NAME));
        mFontBConfig.setBootloaderVersion(getString(getContext(),NAME,BOOTLOADER_VERSION));
        mFontBConfig.setFontName(getString(getContext(),NAME,FONT_NAME));
        mFontBConfig.setFontVersion(getString(getContext(),NAME,FONT_NAME_VERSION));
        mFontBConfig.setFirewareNewPath(getString(getContext(),NAME,FIREWARE_NEW_PATH));
        mFontBConfig.setBootloaderPath(getString(getContext(),NAME,BOOTLOADER_PATH));
        mFontBConfig.setFontPath(getString(getContext(),NAME,FONT_PATH));
        mFontBConfig.setDeviceId(getString(getContext(),NAME,DEVICE_ID));
        return mFontBConfig;
    }

}
